/* lfsystest.c - lfsystest.c */

#include <xinu.h>
#include <stdio.h>
#include <string.h>

/*------------------------------------------------------------------------
 * lfsystest - test local file system
 *------------------------------------------------------------------------
 */
syscall lfsystest(void)
{
	did32 fd1, fd2;
	char input[100000], output[100000];
	int i;
	struct lflcblk *lfptr;
	//struct ldentry *ldptr;
	
	for(i=0;i<100000;i++) {
		input[i] = (char)(i%256);
		output[i] = ' ';
	}
	
	open(RAMDISK, "1000", NULL);
	lfscreate(RAMDISK, 100, 512000);
	fd1 = open(LFILESYS, "myfile1", "rw");
	
	lfptr = &lfltab[devtab[fd1].dvminor];
	kprintf("Intially:\r\n");
	kprintf("ID of current index block = %d\r\n", lfptr->lfinum);
	kprintf("ID of current data block = %d\r\n", lfptr->lfdnum);
	kprintf(" Byte position of next byte = %d\r\n\r\n", lfptr->lfpos);

	write(fd1, input, 100000);
	kprintf("After writing 100000 bytes:\r\n");
	kprintf("ID of current index block = %d\r\n", lfptr->lfinum);
	kprintf("ID of current data block = %d\r\n", lfptr->lfdnum);
	kprintf(" Byte position of next byte = %d\r\n\r\n", lfptr->lfpos);
	seek(fd1, 0);
	kprintf(" Byte position of next byte = %d\r\n\r\n", lfptr->lfpos);
	read(fd1, output, 100000);
	kprintf("After reading 100000 bytes:\r\n");
	kprintf("ID of current index block = %d\r\n", lfptr->lfinum);
	kprintf("ID of current data block = %d\r\n", lfptr->lfdnum);
	kprintf(" Byte position of next byte = %d\r\n\r\n", lfptr->lfpos);
	
	for(i=0;i<100000;i++) {
		//printf("input=%c, output=%c\r\n", input[i], output[i]);
		if (input[i] != output[i])
			printf("Wrong");
	}
	
	fd2 = open(LFILESYS, "myfile1", "rw");
	
	return OK;
}
